import store from '@/store'
import request from '@/utils/request'

export const registerAPI = (data) => {
  return request.post('/api/reg', data)
}

export const loginAPI = (data) => {
  return request.post('/api/login', data)
}
// 获取用户基本资料
export const getUserInfoAPI = () => {
  return request.get('/my/userinfo', {
    headers: {
      Authorization: store.state.token
    }
  })
}

export const getMenusAPI = () => {
  return request.get('/my/menus', {
    headers: {
      Authorization: store.state.token
    }
  })
}
// 更新用户基本资料
export const updateUserInfoAPI = (data) => {
  return request.put('/my/userinfo', data)
}

// 更新用户头像
export const updateAvatarAPI = data => {
  return request.patch('/my/update/avatar', data)
}
export const updatePwdAPI = data => {
  return request.patch('/my/updatepwd', data)
}

// 获取文章分类
export const getArtCateListAPI = () => {
  return request.get('/my/cate/list')
}

// 增加文章
export const addCateListAPI = data => {
  return request.post('/my/cate/add', data)
}

// 修改文章分类
export const updateArtCateAPI = (data) => {
  return request.put('/my/cate/info', data)
}

// 删除分类
export const delArtCateAPI = id => {
  return request.delete('/my/cate/del', {
    params: {
      id
    }
  })
}

// 发布文章
export const uploadArticleAPI = data => {
  return request.post('/my/article/add', data)
}

// export const uploadArticleAPI = (fd) => {
//   return request({
//     url: '/my/article/add',
//     method: 'POST',
//     data: fd // 参数要的是表单对象, 不能写普通对象, axios内部会判断, 如果是表单对象, 传递的请求体会设置Content-Type: form-data与后端对应
//   })
// }

// 获取文章列表

export const getArticleListAPI = (params) => {
  return request.get('/my/article/list', { params })
}

// 获取文章详情
export const getArticleDetailAPI = id => {
  return request.get('/my/article/info', {
    params: {
      id
    }
  })
}

// 删除文章
export const delArticleAPI = id => {
  return request.delete('/my/article/info', {
    params: {
      id
    }
  })
}
